#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:lxl

import tkinter as tk  # 使用Tkinter前需要先导入


class Window:

    def __init__(self, title, geometry):
        self.title = title
        self.geometry = geometry

    @staticmethod
    def canvas(self):
        window = tk.Tk()
        window.title(self.title)
        window.geometry(self.geometry)

        canvas = tk.Canvas(window, bg='green', height=200, width=500)
        file = tk.PhotoImage(file="1.png")
        canvas.create_image(250, 0, anchor='n', image=file)
        x0, y0, x1, y1 = 100, 100, 150, 150
        line = canvas.create_line(x0 - 50, y0 - 50, x1 - 50, y1 - 50)  # 画直线
        oval = canvas.create_oval(x0 + 120, y0 + 50, x1 + 120, y1 + 50, fill='yellow')  # 画圆 用黄色填充
        arc = canvas.create_arc(x0, y0 + 50, x1, y1 + 50, start=0, extent=180)  # 画扇形 18度打开收到180度结束
        rect = canvas.create_rectangle(330, 30, 330 + 20, 30 + 20)  # 画矩形正方形
        canvas.pack()

        def moveit():
            canvas.move(rect, 2, 2)  #

        b = tk.Button(window, text='move item', command=moveit).pack()

        window.mainloop()


if __name__ == '__main__':
    r = Window(title="canvas", geometry="500x300")
    r.canvas(r)
